package com.dream.myqiyi.channel;

import java.util.ArrayList;
import java.util.HashMap;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.boyle.musicplayer.MainActivity;
//import com.boyle.musicplayer.OtherUi;
import com.boyle.util.adapter.LazyAdapter;
import com.boyle.utils.XMLParser;
import com.dream.myqiyi.R;
import com.dream.myqiyi.account.AccountActivity;
import com.dream.myqiyi.account.ZiyuanmingxiActivity;
import com.dream.myqiyi.search.GudingzichanActivity;
import com.dream.myqiyi.search.XianjinActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class ChannelActivity extends Activity {
	GridView mHotGridView, mHistoryGridView;
	TextView mTitleView;
//	static final String URL = "http://192.168.1.100/music.xml";
//	// XML 鑺傜偣
//	public static final String KEY_SONG = "song"; // parent node
//	public static final String KEY_ID = "id";
//	public static final String KEY_TITLE = "title";
//	public static final String KEY_ARTIST = "artist";
//	public static final String KEY_DURATION = "duration";
//	public static final String KEY_THUMB_URL = "thumb_url";

//	ListView list;
//	LazyAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.zcgs);
		prepareView();
		mTitleView.setText(R.string.category_channel);
		
		RelativeLayout mRelativeLayout1 = (RelativeLayout)findViewById(R.id.cw);
		RelativeLayout mRelativeLayout2 = (RelativeLayout)findViewById(R.id.sr);
		RelativeLayout mRelativeLayout3 = (RelativeLayout)findViewById(R.id.zc);
		RelativeLayout mRelativeLayout4 = (RelativeLayout)findViewById(R.id.zq);
		RelativeLayout mRelativeLayout5 = (RelativeLayout)findViewById(R.id.sy);
		RelativeLayout mRelativeLayout6 = (RelativeLayout)findViewById(R.id.qtzy);
		
		mRelativeLayout1.setOnClickListener(listener);
		mRelativeLayout2.setOnClickListener(listener);
		mRelativeLayout3.setOnClickListener(listener);
		mRelativeLayout4.setOnClickListener(listener);
		mRelativeLayout5.setOnClickListener(listener);
		mRelativeLayout6.setOnClickListener(listener);
	}
		
		/***
		 * 所有模块的点击监听
		 * **/
		OnClickListener listener=new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				switch (v.getId()) {
				case R.id.cw:
					//财务计划
					Intent cwintent = new Intent();
					cwintent.setClass(ChannelActivity.this, GudingzichanActivity.class);
					startActivity(cwintent);
					break;
				case R.id.sr:
					//收入
					Intent srintent = new Intent();
					srintent.setClass(ChannelActivity.this, XianjinActivity.class);
					srintent.putExtra("listType", "1");
					startActivity(srintent);
					break;
					
				case R.id.zc:
					//支出
					Intent zcintent = new Intent();
					//wzintent.setClass(ChannelActivity.this, ChanpinwuziActivity.class);
					zcintent.setClass(ChannelActivity.this, XianjinActivity.class);
					zcintent.putExtra("listType", "2");
					startActivity(zcintent);
				    break;
				case R.id.zq:
					//债权
					Intent zqintent = new Intent();
					//nyintent.setClass(ChannelActivity.this, NyzichanActivity.class);
					zqintent.setClass(ChannelActivity.this, XianjinActivity.class);
					zqintent.putExtra("listType", "3");
					startActivity(zqintent);
					break;
				case R.id.sy:
					//收益
					Intent syintent = new Intent();
					//dwintent.setClass(ChannelActivity.this, DuiwaitouziActivity.class);
					syintent.setClass(ChannelActivity.this, XianjinActivity.class);
					syintent.putExtra("listType", "4");
					startActivity(syintent);
					break;
				case R.id.qtzy:
					//其他资金
					Intent qtzyintent = new Intent();
					//tzintent.setClass(ChannelActivity.this, QitazichanActivity.class);
					qtzyintent.setClass(ChannelActivity.this, XianjinActivity.class);
					qtzyintent.putExtra("listType", "6");
					startActivity(qtzyintent);
					break;
					

				default:
					break;
				}
				
			}
		};
		
//		RelativeLayout  cw  = (RelativeLayout ) findViewById(R.id.cw);
//		RelativeLayout  gx  = (RelativeLayout ) findViewById(R.id.sr);
//		RelativeLayout  zc = (RelativeLayout ) findViewById(R.id.zc);
//		RelativeLayout  zq  = (RelativeLayout ) findViewById(R.id.zq);
//		RelativeLayout  sy  = (RelativeLayout ) findViewById(R.id.sy);
//		RelativeLayout  qtzy  = (RelativeLayout ) findViewById(R.id.qtzy);
//	
//		cw.setOnClickListener(new View.OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				// TODO Auto-generated method stub
//				Intent intent = new Intent();
//				intent.setClass(ChannelActivity.this, CaiwujihuaActivity.class);
//				startActivity(intent);
//			}
//		});
//		
//		gx.setOnClickListener(new View.OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				// TODO Auto-generated method stub
//				Intent intent = new Intent();
//				intent.setClass(ChannelActivity.this, GxshouruActivity.class);
//				startActivity(intent);
//			}
//		});
//		
//		zc.setOnClickListener(new View.OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				// TODO Auto-generated method stub
//				Intent intent = new Intent();
//				intent.setClass(ChannelActivity.this, GxzhichuActivity.class);
//				startActivity(intent);
//			}
//		});
//		zq.setOnClickListener(new View.OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				// TODO Auto-generated method stub
//				Intent intent = new Intent();
//				intent.setClass(ChannelActivity.this, ZqzwActivity.class);
//				startActivity(intent);
//			}
//		});
//		sy.setOnClickListener(new View.OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				// TODO Auto-generated method stub
//				Intent intent = new Intent();
//				intent.setClass(ChannelActivity.this, ShouyifenpeiActivity.class);
//				startActivity(intent);
//			}
//		});
//		qtzy.setOnClickListener(new View.OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				// TODO Auto-generated method stub
//				Intent intent = new Intent();
//				intent.setClass(ChannelActivity.this, QitazijinActivity.class);
//				startActivity(intent);
//			}
//		});
		
		
//		cw.setOnTouchListener(new TouhListener());
//		gx.setOnTouchListener(new LqListener());
//		zc .setOnTouchListener(new GqListener());
//		zq.setOnTouchListener(new TdListener());
//		sy .setOnTouchListener(new ZjdListener());
		//hz.setOnTouchListener(new QtdListener());
	   //     hz .setOnTouchListener(new HzListener());
	        
		
	
	
//	private final class TouhListener implements OnTouchListener{
//
//		public boolean onTouch(View v, MotionEvent event) {
//			Toast.makeText(getApplicationContext(), "---- OnTouchListener -----", event.getAction()).show();
//	          Intent intent = new Intent();
//	          intent.setClass(getApplicationContext(), ChannelActivity.class);
//	          startActivity(intent);
//	          overridePendingTransition(android.R.anim.fade_in,
//						android.R.anim.fade_out); 
//			return false;
//		}}
//	private final class LqListener implements OnTouchListener{
//
//		@Override
//		public boolean onTouch(View v, MotionEvent event) {
//			// TODO Auto-generated method stub
//			Intent intent = new Intent();
//	          intent.setClass(getApplicationContext(), ChannelActivity.class);
//	          startActivity(intent);
//	          overridePendingTransition(android.R.anim.fade_in,
//						android.R.anim.fade_out); 
//			
//			return false;
//		}}
//	private final class GqListener implements OnTouchListener{
//
//		@Override
//		public boolean onTouch(View v, MotionEvent event) {
//			// TODO Auto-generated method stub
//			Intent intent = new Intent();
//	          intent.setClass(getApplicationContext(), ChannelActivity.class);
//	          startActivity(intent);
//	          overridePendingTransition(android.R.anim.fade_in,
//						android.R.anim.fade_out); 
//			
//			return false;
//		}}
//	private final class TdListener implements OnTouchListener{
//
//		@Override
//		public boolean onTouch(View v, MotionEvent event) {
//			Intent intent = new Intent();
//	          intent.setClass(getApplicationContext(), ChannelActivity.class);
//	          startActivity(intent);
//	          overridePendingTransition(android.R.anim.fade_in,
//						android.R.anim.fade_out); 
//			return false;
//		}}
//	private final class ZjdListener implements OnTouchListener{
//
//		@Override
//		public boolean onTouch(View v, MotionEvent event) {
//			Intent intent = new Intent();
//	          intent.setClass(getApplicationContext(), ChannelActivity.class);
//	          startActivity(intent);
//	          overridePendingTransition(android.R.anim.fade_in,
//						android.R.anim.fade_out); 
//			return false;
//		}}
//	private final class HzListener implements OnTouchListener{
//
//		@Override
//		public boolean onTouch(View v, MotionEvent event) {
//			Intent intent = new Intent();
//	          intent.setClass(getApplicationContext(), ChannelActivity.class);
//	          startActivity(intent);
//	          overridePendingTransition(android.R.anim.fade_in,
//						android.R.anim.fade_out); 
//			return false;
//		}}
//	private final class QtdListener implements OnTouchListener{
//
//		public boolean onTouch(View v, MotionEvent event) {
//			Toast.makeText(getApplicationContext(), "---- OnTouchListener -----", event.getAction()).show();
//	          Intent intent = new Intent();
//	          intent.setClass(getApplicationContext(), ChannelActivity.class);
//	          startActivity(intent);
//	          overridePendingTransition(android.R.anim.fade_in,
//						android.R.anim.fade_out); 
//			return false;
//		}}
	/*	new Thread(new Runnable() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				Message msg = new Message();
				msg.what = 0;
				
				//鑾峰彇姝屾洸鍒楄〃
				msg.obj = getList();
				handler.sendMessage(msg);
			}
		}).start();
	}

	private Handler handler = new Handler(){
		public void handleMessage(Message msg) {
			switch(msg.what){
			case 0 :
				list = (ListView) findViewById(R.id.list);
				
				ArrayList<HashMap<String, String>> songsList = (ArrayList<HashMap<String, String>>)msg.obj;
				adapter = new LazyAdapter(ChannelActivity.this, songsList);
				list.setAdapter(adapter);

				// 自由发挥
				list.setOnItemClickListener(new OnItemClickListener() {

					@Override
					public void onItemClick(AdapterView<?> parent, View arg1,
							int arg2, long arg3) {
						// TODO Auto-generated method stub
						ListView lview=(ListView)parent;
						Toast.makeText(getApplicationContext(), "点了我哦", 1).show();
						Intent intent=new Intent();
						intent.setClass(getApplicationContext(),OtherUi.class);
						startActivity(intent);
					}
				});
				
			}
		}
	};
	
	// 涓篖istView鍒楁坊鍔犲崟鍑讳簨浠�
	class ListViewItemOnClickListener implements OnItemClickListener {
		@Override
		public void onItemClick(AdapterView<?> parent, View view,
				int position, long id) {
			
			System.out.println("----->OnClick");
			// 杩欓噷鍙互鑷敱鍙戞尌锛屾瘮濡傛挱鏀句竴棣栨瓕鏇茬瓑绛�
		}
	}
	
	// 鑾峰彇姝屾洸鍒楄〃
	private ArrayList<HashMap<String, String>> getList() {
		ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();

		XMLParser parser = new XMLParser();
		String xml = parser.getXmlFromUrl(URL); // 浠庣綉缁滆幏鍙朮ML
		Document doc = parser.getDomElement(xml); // 鑾峰彇 DOM 鑺傜偣

		NodeList nl = doc.getElementsByTagName(KEY_SONG);
		// 寰幆閬嶅巻鎵�湁鐨勬瓕鑺傜偣 <song>
		for (int i = 0; i < nl.getLength(); i++) {
			// 鏂板缓涓�釜 HashMap
			HashMap<String, String> map = new HashMap<String, String>();
			Element e = (Element) nl.item(i);
			// 姣忎釜瀛愯妭鐐规坊鍔犲埌HashMap鍏抽敭= >鍊�
			map.put(KEY_ID, parser.getValue(e, KEY_ID));
			map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
			map.put(KEY_ARTIST, parser.getValue(e, KEY_ARTIST));
			map.put(KEY_DURATION, parser.getValue(e, KEY_DURATION));
			map.put(KEY_THUMB_URL, parser.getValue(e, KEY_THUMB_URL));

			// HashList娣诲姞鍒版暟缁勫垪琛�
			songsList.add(map);
		}
		return songsList;
	}


//	public boolean onCreateOptionsMenu(Menu menu) {
//		
//		getMenuInflater().inflate(R.menu.main, menu);
//		return true;
//	}
		
		*/
	

	private void prepareView() {
		mTitleView = (TextView) findViewById(R.id.title_text);
	}
	
}
